/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-07-08     86188       the first version
 */


#include <inc/filter.h>



///低通滤波
float LowPassFilter(filter_t *f){

    f->output = (f->alpha * f->input) + ((1-f->alpha) * f->prev_input);

     f->prev_input = f->output;

     return  f->output;


}

float LowPassFilter2(filter_t *f)
{
     f->output = (f->alpha * f->input) + (((1-f->alpha) *0.7f) * f->prev_input) + (((1-f->alpha)*0.3f) * f->prev_input2);

     f->prev_input2 = f->prev_input;
     f->prev_input = f->output;



     return  f->output;
}

///冒泡 10   /2
float bubbleSort(float arr[], uint8_t n) {

    uint8_t i,j,k,cnt = n/10 * 4;
        float temp;
        float sum=0;

    for (i = 0; i < n - 1; i++)
        {
        for (j = 0; j < n - i - 1; j++)
                {
            if (arr[j] > arr[j + 1])
                        {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }
        ///  3456   7
        for(k = 0; k < cnt; k++)
        {
            sum += arr[cnt -1 + k];
        }

        return (uint32_t)sum/(cnt);
}


